package com.ddz.fightthelandlord;

import java.util.List;

import android.graphics.Color;
import android.graphics.Paint;

import com.ddz.implementation.GameBase;
import com.ddz.implementation.Graphics;
import com.ddz.implementation.Graphics.ImageFormat;
import com.ddz.interfaces.IInput.TouchEvent;
import com.ddz.interfaces.State;

public class MainMenuState extends State {

	Paint mPaint = new Paint();

	public MainMenuState(GameBase _game) {
		super(_game);
	}

	@Override
	public void onInit() {
		AssetManager.gameboard = game.getGraphics().newImage("Background.png",
				ImageFormat.RGB565);
		mPaint.setColor(Color.WHITE);
		mPaint.setTextSize(50.0f);
		mPaint.setUnderlineText(true);
	}

	@Override
	public void onUpdate(float deltaTime) {
		Graphics g = game.getGraphics();

		List<TouchEvent> touchEvents = game.getInput().getTouchEvents();

		int length = touchEvents.size();
		for (int iter = 0; iter < length; iter++) {
			TouchEvent event = touchEvents.get(iter);
			int top = (int) game.getDisplayBounds().top;
			int left = (int) game.getDisplayBounds().left;
			if (inBounds(event, left + 300, top + 350, 500, 100)) {
				android.os.Process.killProcess(android.os.Process.myPid());
			}
		}

	}

	@Override
	public void onPaint(float deltaTime) {
		Graphics g = game.getGraphics();
		g.drawImage(AssetManager.gameboard, 0, 0);
		int top = (int) game.getDisplayBounds().top;
		int left = (int) game.getDisplayBounds().left;
		// Play
		g.drawRect(left + 150, top + 100, 500, 100, Color.GRAY);
		g.drawString("Play", left + 300, top + 150, mPaint);

		// Exit
		g.drawRect(left + 150, top + 300, 500, 100, Color.GRAY);
		g.drawString("Exit", left + 300, top + 350, mPaint);
	}

	@Override
	public void onPause() {
	}

	@Override
	public void onResume() {
	}

	@Override
	public void dispose() {
	}

	@Override
	public void backButton() {
	}
}
